package com.yunsc.admin.controller.product;

import com.yunsc.common.utils.PageResult;
import com.yunsc.common.utils.Result;
import com.yunsc.common.utils.SecurityUtil;
import com.yunsc.common.validator.ValidationGroups;
import com.yunsc.product.dto.CommentDTO;
import com.yunsc.product.dto.QueryCommentDTO;
import com.yunsc.product.service.YunscCommentService;
import com.yunsc.product.vo.GoodsCommentVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;


/**
 * 商品评价记录表
 *
 * @author adan
 * @email 2028038953@gmail.com
 * @date 2023-12-19 02:17:44
 */
@Api(tags = "商品信息管理", value = "商品评价记录接口")
@RestController
@RequestMapping("goods/comment")
public class CommentController {
    @Resource
    private YunscCommentService commentService;

    /**
     * 列表
     */
    @ApiOperation(value = "商品评价记录列表", notes = "商品评价记录列表")
    @GetMapping("/list")
    public Result<?> queryCommentList(QueryCommentDTO commentDTO) {
        Integer currentStoreId = SecurityUtil.getCurrentStoreId();
        PageResult<GoodsCommentVO> commentPage = commentService.queryCommentList(commentDTO, currentStoreId);
        return Result.resultPageList(commentPage);
    }

    @ApiOperation(value = "商品评价详情", notes = "商品评价详情")
    @GetMapping("/detail")
    public Result<?> queryGoodsCommentDetail(@RequestParam("commentId") Integer commentId) {
        GoodsCommentVO comment = commentService.queryCommentDetail(commentId);
        Map<String, Object> map = new HashMap<>();
        map.put("detail", comment);
        return Result.ok(map);
    }

    @ApiOperation(value = "编辑评价", notes = "编辑评价")
    @PostMapping("/edit")
    public Result<?> editComment(@RequestBody() @Validated({ValidationGroups.Update.class})  CommentDTO params) {
        commentService.editComment(params);
        return Result.ok();
    }

    @ApiOperation(value = "删除评价", notes = "删除评价")
    @PostMapping("/delete")
    public Result<?> deleteComment(@RequestBody() @Validated({ValidationGroups.Delete.class}) CommentDTO params){
        commentService.deleteComment(params.getCommentId());
        return Result.ok();
    }

}
